package cn.cyb.server.service.impl;

import cn.cyb.server.domain.entity.SysRole;
import cn.cyb.server.mapper.SysRoleMapper;
import cn.cyb.server.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author yuebo
 * @date 2025/3/4
 */
@Service
public class SysRoleServiceImpl implements ISysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public Set<String> selectRolePermissionByUserId(Long userId) {
        List<SysRole> roleList = sysRoleMapper.selectRolePermissionByUserId(userId);
        Set<String> permissionSet = new HashSet<>();
        for (SysRole role : roleList) {
            String roleKey = role.getRoleKey();
            String[] split = roleKey.trim().split(",");
            permissionSet.addAll(Arrays.asList(split));
        }
        return permissionSet;
    }
}
